<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="../header.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${systemName }</title>
    <link rel="shortcut icon" href="${contextPath}/resources/favicon.ico"> 
    <link href="${contextPath}/resources/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${contextPath}/resources/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <!-- Data Tables -->
    <link href="${contextPath}/resources/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${contextPath}/resources/css/animate.min.css" rel="stylesheet">
    <link href="${contextPath}/resources/css/style.min.css?v=4.1.0" rel="stylesheet">
    <!-- FooTable -->
    <link href="${contextPath}/resources/css/plugins/footable/footable.core.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
       <div class="row">
          <div class="col-lg-12">
              <div class="ibox float-e-margins">
                  <div class="ibox-title">
                      <form role="form" class="form-inline" action="${contextPath}/system/order/list">
                          <div class="form-group">
                              <input type="text" name="userId" value="${goodsReq.userId }" placeholder="用户ID" class="form-control input-sm">
                          </div>
                          <div class="form-group">
                          	<label>订单状态:</label>
                          	<select class="form-control" name="orderStatus">
		                    	<c:forEach items="${shippingChannels }" var="sc" varStatus="vs">
		                    	<option value="${sc.id }">${sc.name }</option>
		                    	</c:forEach>
		                    </select>
                          </div>
                          <div class="form-group">
                              <input class="btn btn-primary btn-sm" type="submit" value="搜索"/>
                          </div>
                      </form>
                  </div>
                  <div class="ibox-content">
                      <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="10">
                          <thead>
                          <tr>
                              <th data-toggle="true">ID</th>
                              <th>订单号</th>
                              <th>订单标题</th>
                              <th>用户ID</th>
                              <th>商品数目</th>
                              <th>订单金额</th>
                              <th>运费</th>
                              <th data-hide="all">总金额</th>
                              <th>订单状态</th>
                              <th data-hide="all">发货信息</th>
                              <th>操作</th>
                          </tr>
                          </thead>
                          <tbody>
							<c:forEach items="${list }" var="order" varStatus="vs">
								<tr>
									<td>${order.id}</td>
									<td>${order.orderNo}</td>
									<td><c:choose>
											<c:when test="${fn:length(order.orderTitle) > 10}">
												<c:out
													value="${fn:substring(order.orderTitle, 0, 10)}......" />
											</c:when>
											<c:otherwise>
												<c:out value="${order.orderTitle}" />
											</c:otherwise>
										</c:choose></td>
									<td>${order.userId}</td>
									<td>${order.goodsNumber }</td>
									<td>${order.orderPayee }</td>
									<td>${order.shippingPayee }</td>
									<td>${order.totalPayee }</td>
									<td><c:choose>
											<c:when test="${order.orderStatus == -1 }">已取消</c:when>
											<c:when test="${order.orderStatus == -2 }">过期取消</c:when>
											<c:when test="${order.orderStatus == 0 }">待付款</c:when>
											<c:when test="${order.orderStatus == 1 }">待收货</c:when>
											<c:when test="${order.orderStatus == 2 }">已发货</c:when>
											<c:when test="${order.orderStatus == 3 }">已完成</c:when>
										</c:choose></td>
									<td>-${order.shippingStatus }-
									<c:if test="${order.shippingStatus eq 0}">未发货</c:if>
									<c:if test="${!(order.shippingStatus eq 0)}">
									<table class="table">
			                            <thead>
			                            <tr>
			                                <th>物流渠道</th>
			                                <th>运单号</th>
			                                <th>发货时间</th>
			                                <th>快递状态</th>
			                            </tr>
			                            </thead>
			                            <tbody>
			                            <tr>
			                                <td>
			                                <c:forEach items="${shippingChannels }" var="sc" varStatus="vs">
						                  	<c:if test="${sc.id eq order.shippingChannel }">${sc.name }</c:if>
						                  	</c:forEach>
			                                </td>
			                                <td>${order.shiippingSn }</td>
			                                <td>
			                                <fmt:formatDate value="${order.shippingTime}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
			                                <td>
			                                <c:if test="${order.shippingStatus eq 0}">未发货</c:if>
			                                <c:if test="${order.shippingStatus eq 1}">已发货</c:if>
			                                <c:if test="${order.shippingStatus eq 2}">已收货</c:if>
			                                </td>
			                            </tr>
			                            </tbody>
			                          </table> 
									</c:if>
									</td>
									<td><a
										href="${contextPath}/system/order/detail/${order.id}"
										class="btn btn-primary btn-xs">查看</a> <c:choose>
											<c:when test="${order.orderStatus == -1 }"></c:when>
											<c:when test="${order.orderStatus == -2 }"></c:when>
											<c:when test="${order.orderStatus == 0 }">
												<a href="${contextPath}/system/order/detail/${order.id}"
													class="btn btn-primary btn-xs">取消订单</a>
											</c:when>
											<c:when test="${order.orderStatus == 1 }">
												<a href="javascript:void(0);" class="btn btn-primary btn-xs" onclick="showModal(${order.id})">发货</a>
											</c:when>
											<c:when test="${order.orderStatus == 2 }">
												<a href="${contextPath}/system/order/detail/${order.id}"
													class="btn btn-primary btn-xs">完成订单</a>
											</c:when>
											<c:when test="${order.orderStatus == 3 }"></c:when>
										</c:choose>
									</td>
								</tr>
							</c:forEach>
						</tbody>
                          <tfoot>
                          <tr>
                              <td colspan="10">
                                  <ul class="pagination pull-right"></ul>
                              </td>
                          </tr>
                          </tfoot>
                      </table>
                  </div>
              </div>
          </div>
      </div>
    </div>
    <div class="modal inmodal" id="myModal4" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<form action="${contextPath }/system/order/update_shipping" class="form-horizontal" method="post" id="saveBannerImg" enctype="multipart/form-data">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<h4>发货</h4>
				</div>
				<div class="modal-body">
					<label>物流渠道:</label>
					<select class="form-control" name="orderStatus" name="shippingChannel">
					<c:forEach items="${shippingChannels }" var="sc" varStatus="vs">
                  	<option value="${sc.id }">${sc.name }</option>
                  	</c:forEach>
                    </select>
                    <label>运单号:</label>
					<input type="text" name="shiippingSn"  id="shiippingSn" class="form-control input-sm"/>
				</div>
				<div class="modal-footer">
					<input type="hidden" name="id"  id="orderIdHiddenInput"/>
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" onclick="saveOrderFlow()">确认发货</button>
				</div>
			</div>
			</form>
		</div>
	</div>
    <script src="${contextPath}/resources/js/jquery.min.js?v=2.1.4"></script>
    <script src="${contextPath}/resources/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${contextPath}/resources/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="${contextPath}/resources/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${contextPath}/resources/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${contextPath}/resources/js/content.min.js?v=1.0.0"></script>
    <!-- FooTable -->
    <script src="${contextPath}/resources/js/plugins/footable/footable.all.min.js"></script>
    <!-- Page-Level Scripts -->
    <script>
    	var orderId = 0;
        $(document).ready(function() {
            $('.footable').footable();
        });
        function showModal(id){
			orderId = id;
			$('#myModal4').modal('show')
		}
        function saveOrderFlow() {
			var bannerImg = $("#shiippingSn").val();
			console.info(orderId);
			if(bannerImg == ''){
				alert("运单号不能为空");
				return false;
			}
			$("#orderIdHiddenInput").val(orderId);
			$("#saveBannerImg").submit();
		}
    </script>
</body>
</html>
